package com.guigu.pd.base.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.guigu.common.utils.PageVo;
import com.guigu.pd.base.common.CustomIdGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.guigu.pd.base.entity.TransportLineTypeEntity;
import com.guigu.pd.base.service.TransportLineTypeService;
import com.guigu.common.utils.R;



/**
 * 线路类型表
 *
 * @author deyran
 * @email deyran@gmail.com
 * @date 2022-07-19 19:09:01
 */
@Api(tags = "线路类型管理")
@RestController
@RequestMapping("base/transportlinetype")
public class TransportLineTypeController {
    @Autowired
    private TransportLineTypeService transportLineTypeService;


    @Autowired
    private CustomIdGenerator customIdGenerator;


    /**
     * 添加线路类型
     *
     * @return 线路类型信息
     */
    @ApiOperation("添加线路类型")
    @PostMapping("/saveTransportLineType")
    public R saveTransportLineType(@RequestParam Map<String, Object> params) {
        TransportLineTypeEntity
                transportLineType = JSON.parseObject(JSON.toJSONString(params),
                TransportLineTypeEntity.class);
        transportLineType.setId(customIdGenerator.nextId(transportLineType)+"");

        transportLineType.setLastUpdateTime(new Date());
        boolean save = transportLineTypeService.save(transportLineType);
        if(save){
            return R.ok("添加成功");
        }
        return  R.ok("添加失败");
    }



    /**
     * 删除线路类型
     *
     * @param id 线路类型id
     * @return 返回信息
     */
    @ApiOperation("删除线路类型")
    @DeleteMapping("/delectlxlxbyid/{id}")
    public R delectlxlxbyid(@PathVariable(name = "id") String id) {
        boolean b = transportLineTypeService.removeById(id);
        if(b){
            return R.ok("删除成功");
        }
        return R.ok("删除失败");
    }

    /**
     * 根据id获取线路类型详情
     *
     * @param id 线路类型id
     * @return 线路类型详情
     */
    @ApiOperation("根据id获取线路类型详情")
    @GetMapping("/fineTransportLineTypeById/{id}")
    public TransportLineTypeEntity fineTransportLineTypeById(@PathVariable(name = "id") String id) {
        TransportLineTypeEntity byId = transportLineTypeService.getById(id);
        return byId;

    }

    /**
     * 更新线路类型信息
     * @return 线路类型信息
     */
    @ApiOperation("更新线路类型信息")
    @PutMapping("/updateTransportLineTypebyid")
    public R updateTransportLineTypebyid(@RequestParam Map<String, Object> params) {
        TransportLineTypeEntity
                transportLineType = JSON.parseObject(JSON.toJSONString(params),
                TransportLineTypeEntity.class);
        transportLineType.setLastUpdateTime(new Date());
        boolean b = transportLineTypeService.updateById(transportLineType);
        if(b){
            return R.ok("修改成功");
        }
        return R.ok("修改失败");
    }


    /**
     * 获取线路类型分页数据
     * @return
     */
    @ApiOperation("获取线路类型分页数据")
    @GetMapping("/findTransportLineTypeByPage")
    public R findTransportLineTypeByPage(@RequestParam Map<String, Object> params) {

        PageVo<TransportLineTypeEntity> list = transportLineTypeService.findTransportLineTypeByPage(params);

        return R.ok().put("linetype",list);

    }

    /**
     * 获取线路类型列表
     * @return 线路类型列表
     */
    @ApiOperation("获取线路类型列表")
    @GetMapping("/findTransportLineTypeAll")
    public List<TransportLineTypeEntity> findTransportLineTypeAll() {
        return transportLineTypeService.list();
    }



}
